package com.fortune.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fortune.base.BaseAPIExcution;
import com.fortune.common.redis.RedisClient;
import com.fortune.constants.Constants;
import com.fortune.constants.redis.CacheKeys;
import com.fortune.dto.excution.SmsExcution;
import com.fortune.dto.in.sms.ReSetPassWordDto;
import com.fortune.enums.SmsEnum;
import com.fortune.util.QmailUtil;
import com.fortune.util.RandomCodeUtil;

import io.swagger.annotations.Api; 
import io.swagger.annotations.ApiOperation;

@Api(value = "sms", description = "各种场景短信的发送", tags = {"短信"})
@RestController
@RequestMapping("sms")
public class SmsController {
	@Autowired
	private RedisClient redisClient;
	
	@ApiOperation(value = "发送重置密码短信", nickname = "sendResetPasswordSms", notes = "", tags={ "@岳希伟" })
    @PostMapping(value = "code/resetPassword",
        produces = { MediaType.APPLICATION_JSON_VALUE },
        consumes = { MediaType.APPLICATION_JSON_VALUE })
	public BaseAPIExcution<Void> sendResetPasswordSms(@Validated @RequestBody ReSetPassWordDto reSetPassWordDto) {
		String phone = reSetPassWordDto.getPhone();
		String[] phones = {phone};
		int code = RandomCodeUtil.get6RandomCode();
		//boolean flag = QmailUtil.sendModel(phones,String.valueOf(code),Constants.EMAIL_ID );
		boolean flag = true;
		if (!flag) {
			return new SmsExcution<Void>(null,SmsEnum.FALSE);
		}
		redisClient.save(String.valueOf(code), 5, CacheKeys.EMAIL_SEND_CODE, phone);
		return new SmsExcution<Void>(null,SmsEnum.SUCCESS);
	}
}
